package com.green.dao.manage.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.green.common.page.Pagination;
import com.green.dao.impl.BaseDaoImpl;
import com.green.dao.manage.PersonDao;
import com.green.model.manage.Person;
import com.green.model.manage.enums.PositionEnum;



/**
 * 人员
 * 
 */
@Repository("personDao")
public class PersonDaoImpl extends BaseDaoImpl implements PersonDao {
    
	private static final String PREFIX = "com.green.dao.manage.PersonDao.";
	@SuppressWarnings("unchecked")
	@Override
	public List<Person> getLoginUser(Map<String, Object> map) {
		return (List<Person>) selectList("com.green.dao.manage.PersonDao.getLoginUser", map);
	}
	@Override
	public int insertPerson(Person ct) {
		return insert("com.green.dao.manage.PersonDao.insertPerson", ct);
	}

	@Override
	public int updatePerson(Person ct) {
		return update("com.green.dao.manage.PersonDao.updatePerson", ct);
	}

	@Override
	public int deletePerson(Map<String, Object> param) {
		return delete("com.green.dao.manage.PersonDao.deletePerson", param);
	}

	@Override
	public Person getPersonById(String id) {
		return (Person) super.getSqlSession().selectOne("com.green.dao.manage.PersonDao.getPersonById",id);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Person> getPersonList(Map<String, Object> param) {
		return (List<Person>) this.selectList("com.green.dao.manage.PersonDao.getPersonList", param);
	}

	@Override
	public Pagination<Person> getPersonPagination(Pagination<Person> pag,
			Map<String, Object> param) {		 
		return selectList("com.green.dao.manage.PersonDao.getPersonPagination", param, pag);
	}
	
	@Override
	public Pagination<Person> getAreaPersonPagination(Pagination<Person> pag,
			Map<String, Object> param) {		 
		return selectList("com.green.dao.manage.PersonDao.getAreaPersonPagination", param, pag);
	}
	
	@SuppressWarnings("unchecked")
    public  List<Person> queryPersons(Map<String, Object> param){
	    
	    return (List<Person>) super.selectList(PREFIX + "queryPersons", param);
	}
    @SuppressWarnings("unchecked")
    @Override
    public List<Person> queryCitymanager(Map<String, Object> param) {
        
        return (List<Person>) super.selectList(PREFIX + "queryCitymanager", param);
    }
    @SuppressWarnings("unchecked")
    @Override
    public Person queryPersonByCity(String cityName, PositionEnum position) {
        Map<String, Object> param = new HashMap<String, Object>();
        param.put("cityName", cityName);
        param.put("positionName", position.getName());
        List<Person> persons = (List<Person>) super.selectList(PREFIX + "queryCitymanager", param);
        if(persons.size()>0) return persons.get(0);
        return null;
    }
	@Override
	public Person getPersonParentOrgId(String personId) {
		return (Person) super.getSqlSession().selectOne("com.green.dao.manage.PersonDao.getPersonParentOrgId",personId);
	}
	@Override
	public Person getPersonParentPersonId(String personId) {
		return (Person) super.getSqlSession().selectOne("com.green.dao.manage.PersonDao.getPersonParentPersonId",personId);
	}
	
}
